package com.xuecheng.content.controller.api;

import com.xuecheng.base.model.PageParams;
import com.xuecheng.base.model.PageResult;
import com.xuecheng.base.model.RestResponse;
import com.xuecheng.content.model.dto.AddCourseDto;
import com.xuecheng.content.model.dto.CourseBasePageDTO;
import com.xuecheng.content.model.dto.EditCourseDto;
import com.xuecheng.content.model.po.CourseBase;
import com.xuecheng.content.model.po.Teachplan;
import com.xuecheng.content.model.vo.CourseBaseInfoVo;
import com.xuecheng.content.model.vo.TeachPlanTreeVo;
import com.xuecheng.content.service.CourseBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程基本信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
@RequestMapping("course")
@Api(tags = "课程基本信息接口")
public class CourseBaseController {

    @Autowired
    private CourseBaseService  courseBaseService;

    @PostMapping("/list")
    @ApiOperation("分页查询课程基本信息")
    public PageResult<CourseBase> getCourseBasePage(PageParams pageParams,
                                                      @RequestBody CourseBasePageDTO courseBasePageDTO){

        PageResult<CourseBase> pageResult = courseBaseService.queryCourseBasePage(pageParams, courseBasePageDTO);
        return pageResult;

    }


    @PostMapping
    @ApiOperation("新增课程")
    public CourseBaseInfoVo saveCourse(@RequestBody AddCourseDto addCourseDto){

        return courseBaseService.saveCourse(addCourseDto);
    }

    @GetMapping("/{courseId}")
    @ApiOperation("根据id获取课程信息")
    public CourseBaseInfoVo getCourseById(@PathVariable Long courseId){

        return courseBaseService.queryCourseById(courseId);

    }

    @PutMapping
    @ApiOperation("修改课程信息")
    public CourseBaseInfoVo updateCourse(@RequestBody EditCourseDto editCourseDto){

        return courseBaseService.updateCourse(editCourseDto);

    }

    @DeleteMapping("/{courseId}")
    public RestResponse deleteCourse(@PathVariable Long courseId){
        courseBaseService.deleteCourse(courseId);
        return RestResponse.success();


    }



}
